<template>
  <div class="">
    <div>
      <jbstep :activeStep="activeStep" @backStep="backStep"></jbstep>
    </div>
    <div class="check-con">
      <div class="left-tree">
        <MyTree @backStep="backStep" orgType="1" :activeStep="activeStep"></MyTree>
      </div>
      <div class="right-content">
        <div class="check-info">
          <div v-if="activeStep == 0">
            <Tab000 :orgName="props.currentRow.organizationBaseName" :orgId="props.currentRow.creditCode" :examineYear="props.currentRow.examineYear" />
          </div>
          <div v-if="activeStep == 1">
            <Tab011 />
          </div>
          <div v-else-if="activeStep == 2">
            <Tab021 />
          </div>
          <div v-else-if="activeStep == 3">
            <Tab031 />
          </div>
          <div v-else-if="activeStep == 4">
            <Tab032 />
          </div>
          <div v-else-if="activeStep == 5">
            <Tab033 />
          </div>
          <div v-else-if="activeStep == 6">
            <Tab034 />
          </div>
          <div v-else-if="activeStep == 7">
            <Tab035 />
          </div>
          <div v-else-if="activeStep == 8">
            <Tab041 />
          </div>
          <div v-else-if="activeStep == 9">
            <Tab042 />
          </div>
          <div v-else-if="activeStep == 10">
            <Tab043 />
          </div>
          <div v-else-if="activeStep == 11">
            <Tab051 />
          </div>
          <div v-else-if="activeStep == 12">
            <Tab052 />
          </div>
          <div v-else-if="activeStep == 13">
            <Tab053 />
          </div>
          <div v-else-if="activeStep == 14">
            <Tab054 />
          </div>
          <div v-else-if="activeStep == 15">
            <Tab055 />
          </div>
          <div v-else-if="activeStep == 16">
            <Tab056 />
          </div>
          <div v-else-if="activeStep == 17">
            <Tab057 />
          </div>
          <div v-else-if="activeStep == 18">
            <Tab061 />
          </div>
          <div v-else-if="activeStep == 19">
            <Tab071 />
          </div>
          <div v-else-if="activeStep == 20">
            <Tab0151 />
          </div>
          <div v-else-if="activeStep == 21">
            <Tab0161 />
          </div>
          <div v-else-if="activeStep == 22">
            <Tab0171 />
          </div>
          <div v-else-if="activeStep == 23">
            <Tab0172 />
          </div>
        </div>
        <div class="note-box" v-if="activeStep != 0">
          <el-input type="textarea" v-model="textValue" style="width: 100%" :rows="5" placeholder="请输入批注" />
        </div>
      </div>
    </div>

    <div style="margin-top: 30px; text-align: center">
      <el-button  @click="changeStep('prev')">上一步</el-button>
      <el-button @click="changeStep('next')">下一步</el-button>
      <el-button type="primary" @click="saveNote()">保存批注</el-button>
      <el-button type="primary" @click="detailTip()">查看批注</el-button>
      <el-button type="primary" :loading="isLoad" @click="toSubmit()">提交</el-button>
    </div>
  </div>
  <el-dialog title="提交校对" v-model="dialogSubmitVisible" width="600px" top="4vh" append-to-body>
    <div style="height: 100px">
      <el-form ref="checkFormRef" :model="checkForm" label-width="120px" class="demo-ruleForm" status-icon>
        <el-form-item label="校对处理" prop="proofreadStatus">
          <el-radio-group v-model="checkForm.proofreadStatus">
            <el-radio label="1">通过</el-radio>
            <el-radio label="2">不通过</el-radio>
          </el-radio-group>
          <!-- <el-select v-model="checkForm.proofreadStatus" placeholder="请选择" style="width: 100%">
            <el-option label="通过" value="1" />
            <el-option label="不通过" value="2" />
          </el-select> -->
        </el-form-item>
      </el-form>
    </div>
    <div style="margin-top: 30px; text-align: center">
      <el-button type="plain" @click="toClose()">关闭</el-button>
      <el-button type="primary" @click="submitJdForm(checkFormRef)" :loading="saveLoad">提交审核 <i
          class="el-icon-arrow-right el-icon--right"></i></el-button>
    </div>
  </el-dialog>
</template>

<script setup lang="ts">
import { ref, reactive, nextTick, inject, provide } from 'vue'
import APTMethods from '@/api/yearCheck/stOrg'

import jbstep from './step.vue'
import MyTree from '../../../components/myTree.vue'
import Tab000 from './checkItem/tab000.vue' //封面
import Tab011 from './checkItem/tab011.vue' //基础信息
import Tab021 from './checkItem/tab021.vue' //负责人信息
//内部建设
import Tab031 from './checkItem/tab031.vue' //年度登记、备案
import Tab032 from './checkItem/tab032.vue' //本年度会议及换届情况
import Tab033 from './checkItem/tab033.vue' //内部管理情况
import Tab034 from './checkItem/tab034.vue' //机构设置情况
import Tab035 from './checkItem/tab035.vue' //党建工作
//财务会计报告
import Tab041 from './checkItem/tab041.vue' //资产负债表
import Tab042 from './checkItem/tab042.vue' //业务活动表
import Tab043 from './checkItem/tab043.vue' //现金流量表
//业务活动情况
import Tab051 from './checkItem/tab051.vue' //年度总结/计划
import Tab052 from './checkItem/tab052.vue' //相关收支、职能和本年度举办重大业务活动情况
import Tab053 from './checkItem/tab053.vue' //接受捐赠资助和使用情况
import Tab054 from './checkItem/tab054.vue' //举办公益慈善活动情况、公益慈善活动支出
import Tab055 from './checkItem/tab055.vue' //本年度举办或参与研讨、展览、培训、评比达标表彰等活动的情况

import Tab056 from './checkItem/tab056.vue' //支援和计划支援西藏昌都建设
import Tab057 from './checkItem/tab057.vue' //参与和计划乡村振兴工作情况
//接受检查监督
import Tab061 from './checkItem/tab061.vue' //接受监督检查情况

//其他需要说明的情况
import Tab071 from './checkItem/tab071.vue' //其它需要说明的情况

//
import Tab0141 from './checkItem/tab0141.vue' //上年度整改情况
import Tab0151 from './checkItem/tab0151.vue' //年检审核意见
import Tab0161 from './checkItem/tab0161.vue' //承接政府购买
import Tab0171 from './checkItem/tab0171.vue' //附件材料
import Tab0172 from './checkItem/tab0172.vue' //理事监事情况
import { ElMessage, ElMessageBox } from 'element-plus'
import { resolve } from '@antv/x6/lib/registry/node-anchor/util'

const props = defineProps({
  currentRow: {
    type: Object,
    default: {}
  }
})


const emit = defineEmits(['openResult'])
//注入父组件方法
const { closeAllPop } = inject('closeAllPop')
//父组件对子组件提供
// provide('backStep', { backStep });

const activeStep = ref(0)
const textValue = ref('')
const orgName = ref('')
const isLoad = ref(false)
const saveLoad = ref(false)
const dialogSubmitVisible = ref(false) //提交校对
const checkForm = reactive({
  proofreadStatus: '1',
  id: props.currentRow.id
})

orgName.value = props.currentRow.organizationBaseName
// 搜索
const params = ref<any>({
  typeId: 1
})

const changeStep = (step) => {
  if (textValue.value) {
    saveNote().then(() => {
      activeStep.value =
        step === 'prev'
          ? activeStep.value == 0
            ? 0
            : --activeStep.value
          : activeStep.value == 23
            ? 19
            : ++activeStep.value
    })
  } else {
    activeStep.value =
      step === 'prev'
        ? activeStep.value == 0
          ? 0
          : --activeStep.value
        : activeStep.value == 23
          ? 23
          : ++activeStep.value
  }
}
const getDetailInfo = () => {
  const { id, organizationType } = props.currentRow
  let mark = activeStep.value - 0;
  if(mark == 23){
    mark = 25;
  }
  return new Promise((resolve, reject) => {
    APTMethods.getSTInfoByPage({
      id,
      organizationType,
      pageNumberMark: mark  //页码
    }).then((res) => {
      textValue.value = res.annotations && res.annotations.description //批注
      resolve(res)
    })
  })
}

// 提供方法给子组件
provide('getDetailInfo', { getDetailInfo });

const backStep = (index) => {
  activeStep.value = index
  console.log(activeStep.value)
}
//保存批注
const saveNote = () => {
  let mark = activeStep.value - 0;
  if(mark == 23){
    mark = 25;
  }
  return new Promise<void>((resolve, reject) => {
    if (textValue.value) {
      APTMethods.saveTips({
        description: textValue.value,
        id: props.currentRow.id,
        pageNumberMark: mark,
      }).then(() => {
        ElMessage({
          type: 'success',
          message: '批注保存成功'
        })
        resolve()
      })
    } else {
      ElMessage({
        type: 'error',
        message: '请输入批注'
      })
    }
  })
}

const detailTip = () => {
  emit('openResult')
}
//提交校对
const submitJdForm = () => {
  saveLoad.value = true
  return new Promise<void>((resolve, reject) => {
    APTMethods.saveJd({ ...checkForm }).then(() => {
      ElMessage({
        type: 'success',
        message: '提交成功，请刷新页面查看最新数据。'
      })
      saveLoad.value = false
      toClose()
      closeAllPop()
      resolve()
    }).catch(error => {
      saveLoad.value = false
    })
  })
}

const toClose = () => {
  dialogSubmitVisible.value = false;
}
const toSubmit = () => {
  dialogSubmitVisible.value = true
}
</script>
<style>
::v-deep .el-dialog {
  margin-bottom: 0;
}

::v-deep .el-dialog__body {
  padding-top: 0 !important;
}

table.m-table {
  border-spacing: 0px;
  width: 100%;
  border-top: 1px solid #999;
  border-left: 1px solid #999;
  color: #000;

  thead {
    background: #f0f7fc;
    color: rgb(37, 43, 53);

    th {
      border-right: 1px solid #999;
      border-bottom: 1px solid #999;
      text-align: center;
      height: 32px;
    }
  }

  td {
    height: 32px;
    border-right: 1px solid #999;
    border-bottom: 1px solid #999;
    text-align: center;

    &.td-head {
      background: #f0f7fc;
    }
  }
}
</style>
<style lang="scss" scoped>
//隐藏滚轮
::v-deep .el-switch.is-disabled {
  opacity: 1;
}

::v-deep .el-tree-node__content {
  font-size: 12px;
}

::v-deep .el-descriptions__title {
  margin-top: 15px;
}

.check-con {
  width: 100%;
  height: 600px;
  // padding: 0 50px;
  overflow: auto;
  box-sizing: border-box;
  display: flex;

  ::-webkit-scrollbar {
    width: 0;
  }

  //将宽度设为0，滚动条就会隐藏。
  ::-webkit-scrollbar {
    display: none;
  }

  .left-tree {
    width: 280px;
    padding: 20px;
    padding-left: 10px;
    padding-right: 10px;
    margin-right: 10px;
    font-size: 12px;
    box-sizing: border-box;
    height: 600px;
    overflow: auto;
    border: 1px solid #eee;
  }

  .right-content {
    flex: 1;
    height: 600px;
    overflow: auto;
    padding-bottom: 10px;
    box-sizing: border-box;
  }

  .check-info {
    flex: 1;
    padding-right: 20px;
    color: #000;

    >div {
      transition: all 0.5s ease-in-out;
    }
  }

  .note-box {
    margin-top: 30px;
  }
}

.msg-tip {
  padding: 20px 0;
  color: #000;

  font-family: '微软雅黑';
}
</style>
